define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'banner/index' + location.search,
                    add_url: 'banner/add',
                    edit_url: 'banner/edit',
                    del_url: 'banner/del',
                    multi_url: 'banner/multi',
                    import_url: 'banner/import',
                    table: 'banner',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'type', title: __('类型'), searchList: {"1":__('顶部轮播'),"2":__('中间轮播'),"3":__('底部轮播')}, formatter: Table.api.formatter.normal},
                        {field: 'is_jump', title: __('Is_jump'), searchList: {"1":__('Is_jump 1'),"2":__('Is_jump 2'),"3":__('Is_jump 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'circle_id', title: __('Circle_id')},
                        {field: 'goods.goods_name', title: __('产品名'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'add_time', title: __('Add_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'edit_time', title: __('Edit_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $(document).on("change", "#c-is_jump", function(){
                var is_jump=$("#c-is_jump").val();
                console.log(is_jump);
                if(is_jump=='1')
                {
                    //不跳转
                    $("#circles").hide();
                    $("#contents").hide();
                }
                else if(is_jump=='2')
                {
                    //帖子
                    $("#circles").show();
                    $("#contents").hide();
                }
                else
                {
                    //图文
                    $("#circles").hide();
                    $("#contents").show();

                }

            });
            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on("change", "#c-is_jump", function(){
                var is_jump=$("#c-is_jump").val();
                if(is_jump=='1')
                {
                    //不跳转
                    $("#circles").hide();
                    $("#contents").hide();
                }
                else if(is_jump=='2')
                {
                    //帖子
                    $("#circles").show();
                    $("#contents").hide();
                }
                else
                {
                    //图文
                    $("#circles").hide();
                    $("#contents").show();

                }

            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
